package cn.tedu.bonfire.front.content.service.impl;

import cn.tedu.bonfire.front.content.dao.persist.repository.ILikeCollectRepository;
import cn.tedu.bonfire.front.content.pojo.entity.LikeCollect;
import cn.tedu.bonfire.front.content.service.ISaveLCInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SaveLCInfoServiceImpl implements ISaveLCInfoService {
    @Autowired
    private ILikeCollectRepository likeCollectRepository;

    /**
     * 查询数据库里是否有对应的文章点赞收藏数据，有则返回true，无则返回false
     * @param userId
     * @param articleId
     * @return
     */
    @Override
    public Boolean switchUpdateOrInsertArticle(Long userId, Long articleId) {
        Long row = likeCollectRepository.switchUpdateOrInsertArticle(userId, articleId);
        return row > 0;
    }
    /**
     * 更新文章点赞状态
     * @param likeCollect
     * @return
     */
    @Override
    public Boolean updateLikeCollection(LikeCollect likeCollect) {
        int row = likeCollectRepository.updateLikeCollection(likeCollect);
        return row > 0;
    }
    /**
     * 文章点赞存储
     * @param likeCollect
     * @return
     */
    @Override
    public Boolean saveLikeCollection(LikeCollect likeCollect) {
        int row = likeCollectRepository.insert(likeCollect);
        return row > 0;
    }
}
